#include "vertex_types.fxh"
#include "Samplers.fxh"
#include "Functions.fxh"


	// TODO

	float g_Bump=10;

CAL3D_HW_VERTEX_PS RenderCal3DHWVS(CAL3D_HW_VERTEX_VS IN)
{
	CAL3D_HW_VERTEX_PS OUT=(CAL3D_HW_VERTEX_PS)0;
	float3 l_Normal= 0;
	//float3 l_Normal = IN.Normal.xyz;
	float3 l_Tangent=0;
	CalcAnimatedNormalTangent(IN.Normal.xyz, IN.Tangent.xyz, IN.Indices, IN.Weight, l_Normal, l_Tangent);
	float3 l_Position=CalcAnimtedPos(float4(IN.Position.xyz,1.0), IN.Indices, IN.Weight);
	float4 l_WorldPosition=float4(l_Position, 1.0);
	OUT.WorldPosition=mul(l_WorldPosition,g_WorldMatrix);
	OUT.WorldNormal=normalize(mul(l_Normal,g_WorldMatrix));
	OUT.WorldTangent=normalize(mul(l_Tangent,g_WorldMatrix));
	OUT.WorldBinormal=mul(cross(l_Tangent,l_Normal),(float3x3)g_WorldMatrix);
	OUT.UV = IN.TexCoord.xy;
	OUT.HPosition = mul(l_WorldPosition, g_WorldViewProjectionMatrix );
	return OUT;
}

float4 RenderCal3DHWPS(CAL3D_HW_VERTEX_PS IN) : COLOR
{
	//float3 Nn=CalcBumpMap(IN.WorldPosition, IN.WorldNormal, IN.WorldTangent, IN.WorldBinormal, IN.UV);
	
	float3 bump=g_Bump*(tex2D(S1LinearSampler,IN.UV).rgb - float3(0.5,0.5,0.5));
	float3 Nn=normalize(IN.WorldNormal);
	/*Nn = Nn + bump.x*IN.WorldTangent + bump.y*IN.WorldBinormal;
	Nn = normalize(Nn);*/
	float4 l_SpecularColor = 1.0;
	float4 l_DiffuseColor=tex2D(S0LinearSampler, IN.UV);
	//return float4(Nn,1.0);
	return CalcLighting (IN.WorldPosition, Nn, l_DiffuseColor);
	//return float4(1,1,1,1);7//
	//return l_DiffuseColor;
}

technique tecCal3D
{
	pass p0
	{
		VertexShader = compile vs_3_0 RenderCal3DHWVS();
		PixelShader = compile ps_3_0 RenderCal3DHWPS();
	}
}